package com.apache.poi.word.pachong;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: HUANG GY.
 * @Date: 2022/2/14 9:50
 * @Description: com.apache.poi.word.pachong
 */
public class MainTest {


    public static void main(String[] args) {
        String base_url = "http://www.gdxjzx.org/ssglzx/articletiyu/articletiyuzsc_" ;
        for (int i = 9; i < 38; i++) {

        }
        String htmlOut = getHtml(base_url + 1);
        List<String> srclists = getImgSrcListFromHtml(htmlOut);
    }



    /**
     *
     * @Title: getHtml
     * @Description: 获取页面内容
     * @param @param url
     * @param @return  页面内容
     * @return String  返回类型
     * @throws
     */
    public static String getHtml(String url){
        String html = "";
        try {
            html = Jsoup.connect(url).execute().body();
            String str = html.substring(html.indexOf("'")+1);
            String nowUrl = str.substring(0, str.indexOf("'"));
            nowUrl = "http://www.gdxjzx.org" + nowUrl ;
            html = Jsoup.connect(nowUrl).execute().body();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return html;
    }

    /**
     *
     * @Title: getImgSrcListFromHtml
     * @Description: 获取页面内容图片路径
     * @param @param html  页面内容
     * @param @return    图片路径数组
     * @return ArrayList<String>    返回类型
     * @throws
     */
    public static List<String> getImgSrcListFromHtml(String html){
        List<String> list = new ArrayList<>();
        //解析成html页面
        Document document = Jsoup.parse(html);
        //获取目标
        Elements elements = document.select("div [class=title]").select("a");
        int len = elements.size();
        for (int i = 0; i < len; i++) {
            list.add(elements.get(i).attr("href"));
        }
        return list;
    }




}
